// 系统名称搜索建议功能
document.addEventListener('DOMContentLoaded', function() {
    const systemInput = document.getElementById('system_name');
    const suggestionsContainer = document.getElementById('systemSuggestions');

    if (systemInput && suggestionsContainer) {
        // 输入框事件监听
        systemInput.addEventListener('input', function() {
            const value = this.value.toLowerCase();
            const items = suggestionsContainer.getElementsByClassName('system-suggestion-item');

            if (value.trim() === '') {
                suggestionsContainer.style.display = 'none';
                return;
            }

            let hasVisible = false;
            Array.from(items).forEach(item => {
                const text = item.textContent.toLowerCase();
                if (text.includes(value)) {
                    item.style.display = 'block';
                    hasVisible = true;
                } else {
                    item.style.display = 'none';
                }
            });

            suggestionsContainer.style.display = hasVisible ? 'block' : 'none';
        });

        // 点击其他区域关闭建议框
        document.addEventListener('click', function(event) {
            if (!systemInput.contains(event.target) && !suggestionsContainer.contains(event.target)) {
                suggestionsContainer.style.display = 'none';
            }
        });
    }
});

// 选择系统名称
function selectSystem(systemName) {
    const input = document.getElementById('system_name');
    const suggestions = document.getElementById('systemSuggestions');

    if (input && suggestions) {
        input.value = systemName;
        suggestions.style.display = 'none';
    }
}